<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="/css/font-awesome/css/font-awesome.css">
<link rel="stylesheet" type="text/css" media="screen" href="/lib/layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class="form-group">
				<label class="col-md-2 control-label">所属模块</label>
				<div class="col-md-10">
					<select id="moduleId" name="moduleId" class="form-control input-sm" onchange="getParentServer();"></select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">上级服务</label>
				<div class="col-md-10">
					<select id="parentId" name="parentId" class="form-control input-sm"></select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">服务名称</label>
				<div class="col-md-10">
					<input class="form-control" placeholder="服务名称" type="text" name="name" id="name"
						data-bv-notempty="true"
						data-bv-notempty-message="服务名称不能为空">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">服务地址</label>
				<div class="col-md-10">
					<input class="form-control" placeholder="服务地址" type="text" name="path" id="path"
						   data-bv-notempty="true"
						   data-bv-notempty-message="服务地址不能为空">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">排序</label>
				<div class="col-md-10">
					<input class="form-control" placeholder="排序" name="sort" id="sort" type="number" value="100"
						   data-bv-notempty="true"
						   data-bv-notempty-message="排序 不能为空">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">服务描述</label>
				<div class="col-md-10">
					<textarea class="layui-textarea" name="description" id="description"></textarea>
				</div>
			</div>
			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
						<button class="btn btn-primary" onclick="location.href='serverList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="add()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>

	<script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="/js/jq.js"></script>
	<script type="text/javascript" src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="/js/common.js"></script>
	<script type="text/javascript" src="/js/my/ztree-menu.js"></script>
	<script type="text/javascript" src="/lib/layui/layui.js"></script>
	<script type="text/javascript">
		layui.use('layer', function(){
		    var layer = layui.layer;
		});

        initModuleSelect();
		function add() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'post',
				url : '/sys/server',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					layer.msg("添加成功", {shift: -1, time: 1000}, function(){
                        location.href = "serverList.html";
                    });
				}
			});
		}
	</script>
</body>
</html>